package middle;

import com.eclipsesource.json.JsonArray;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * 695. 岛屿的最大面积
 */
public class MaxAreaOfIsland {
    public static int[] stringToIntegerArray(String input) {
        input = input.trim();
        input = input.substring(1, input.length() - 1);
        if (input.length() == 0) {
            return new int[0];
        }

        String[] parts = input.split(",");
        int[] output = new int[parts.length];
        for (int index = 0; index < parts.length; index++) {
            String part = parts[index].trim();
            output[index] = Integer.parseInt(part);
        }
        return output;
    }

    public static int[][] stringToInt2dArray(String input) {
        JsonArray jsonArray = JsonArray.readFrom(input);
        if (jsonArray.size() == 0) {
            return new int[0][0];
        }

        int[][] arr = new int[jsonArray.size()][];
        for (int i = 0; i < arr.length; i++) {
            JsonArray cols = jsonArray.get(i).asArray();
            arr[i] = stringToIntegerArray(cols.toString());
        }
        return arr;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            int[][] grid = stringToInt2dArray(line);

            int ret = maxAreaOfIsland(grid);

            String out = String.valueOf(ret);

            System.out.print(out);
        }
    }

    static int[] mx = new int[]{-1, 0, 1, 0};
    static int[] my = new int[]{0, -1, 0, 1};

    public static int maxAreaOfIsland(int[][] grid) {
        int rows = grid.length;
        int columns = grid[0].length;
        int size = 0;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < columns; j++) {
                if (grid[i][j] == 1) {
                    int temp = dfs(grid, i, j,rows,columns);
                    if (size < temp) {
                        size = temp;
                    }
                }
            }
        }
        return size;
    }

    /**
     * Deep First Search
     *
     * @param image
     * @param sr
     * @param sc
     */
    public static int dfs(int[][] image, int sr, int sc, int rows, int column) {
        int size = 0;
        if (image[sr][sc]==1) {
            size++;
            image[sr][sc] = 0;
            for (int i = 0; i < 4; i++) {
                if (sr + mx[i] >= 0
                        && sr + mx[i] < rows
                        && sc + my[i] >= 0
                        && sc + my[i] < column ) {
                    size+=dfs(image,sr + mx[i],sc + my[i],rows,column);
                }
            }
        }
        return size;
    }

}
